package model;

import java.util.Stack;


/**
 * This class represents the PreOrderTraversal
 * 
 * @author Dustin Meijer, Alexnder Jeurissen.
 *
 */

public class PreOrderTraversal {
	
	private NamedTreeNode root;
	private Stack<NamedTreeNode> nodePath;
	
	public PreOrderTraversal(NamedTreeNode root){
		this.root = root;
		this.nodePath = new Stack<NamedTreeNode>();
	}

	public void traverse(){
		NamedTreeNode current = this.root;
				
		while(current != null || !nodePath.isEmpty()){
			
			if(current != null){
				System.out.println(current.toString());
				nodePath.push(current);
				current = (NamedTreeNode) current.getChildAt(NamedTreeNode.LEFT);
			}else{
				current = (NamedTreeNode) nodePath.pop();
				current = (NamedTreeNode) current.getChildAt(NamedTreeNode.RIGHT);
			}
		}
		
		
// deze werkt met defaultmutable !	
//		while(currentNode != null || !nodePath.isEmpty()){
//			System.out.println(currentNode.toString());
//			if(currentNode.getChildCount() > NO_CHILDREN){
//				nodePath.push(currentNode);
//				currentNode = currentNode.getChildAt(LEFT);
//			}else if(!nodePath.isEmpty()){
//				currentNode = nodePath.pop().getChildAt(RIGHT);
//			}else{
//				currentNode = null;
//			}	
//		}
	}
	
}
